package com.chery.media.utils

import android.content.Context
import android.hardware.usb.UsbManager
import com.blankj.utilcode.util.Utils
import com.chery.media.library.extend.toast
import java.io.File

class StorageManagerUtils {

    /**
     * Uos是否连接
     */
    fun isUsbConnected(): Boolean {
        val usbManager = Utils.getApp().getSystemService(Context.USB_SERVICE) as UsbManager
        val deviceList = usbManager.deviceList
        for (device in deviceList.values) {
            if (usbManager.hasPermission(device)) {
                "Usb已连接".toast()
                "/storage/${device.deviceName}".toast()
                return true
            }
        }
        "Usb未连接".toast()
        return false
    }

    /**
     * 获取U盘根目录
     */
    fun getUsbRootPath(): String {
        val usbManager = Utils.getApp().getSystemService(Context.USB_SERVICE) as UsbManager
        val deviceList = usbManager.deviceList
        for (device in deviceList.values) {
            if (device.vendorId == 0x10c4 && device.productId == 0xea60) {
                return "/storage/${device.deviceName}"
            }
        }
        return ""
    }


    /**
     * 获取U盘音乐文件
     */
    fun getUsbMusicFile(): List<File> {
        return arrayListOf()
    }

}